package com.view.commonView;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 * @author Diego Iacono
 * 
 */
public class ImagePanel extends JPanel
{
   private Image img;

   public ImagePanel(String imgPath)
   {
      this(new ImageIcon(loadPath() + imgPath).getImage());
   }

   public ImagePanel(Image img)
   {
      this.img = img;
      Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
      setPreferredSize(size);
      setMinimumSize(size);
      setMaximumSize(size);
      setSize(size);
      setLayout(null);
   }

   public void paintComponent(Graphics g)
   {
      g.drawImage(img, 0, 0, null);
   }

   private static String loadPath()
   {
      File currentDir = new File("");
      String pathStr = currentDir.getAbsolutePath() + "\\picture\\";
      return pathStr;
   }

}
